package com.gxa.controller;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.gxa.common.JsonResult;
import com.gxa.common.R;
import com.gxa.pojo.Contract;
import com.gxa.pojo.Contract_acc;
import com.gxa.pojo.Contract_renew;
import com.gxa.pojo.Contract_status;
import com.gxa.service.ContractService;
import com.gxa.service.LsFinanceService;
import com.gxa.utils.DateFormatUtils;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Controller
//http://localhost:8080/swagger-ui.html
@Api(value = "系统合同管理数据test",tags = "合同管理数据接口API-王梓鑫")
@RequestMapping(value = "/Contract")

public class ContractController {
    @Autowired
    private ContractService contractService;
    R r = new R();
    Date date =  new Date();


    @RequestMapping(value = "/queryContractMap",method = RequestMethod.GET)
    @ApiOperation(value = "合同管理数据查询接口",notes = "查询系统合同管理数据",httpMethod = "get", response = R.class)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "page",value = "页码数",required = true,dataType = "String",paramType = "query"),
//            @ApiImplicitParam(name = "limit",value = "每页条数",required = true,dataType = "String",paramType = "query")
//    })
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code=500,message = "后台错误")
    })
    @ResponseBody
    //合同管理系统-数据查询-接口12.06
    public JsonResult queryContractMap(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit){

        return contractService.queryContractMap(page,limit);
    }


    @RequestMapping(value = "/updateContractList",method = RequestMethod.POST)
    @ApiOperation(value = "合同管理数据修改接口",notes = "修改系统合同管理数据",httpMethod = "post", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code=500,message = "后台错误")
    })
    @ResponseBody
    //合同管理系统-数据修改-接口  12.07
    public R updateContractList(@RequestBody @ApiParam(name = "contract",value = "修改合同",required = true) Contract contract){
        return contractService.updateContractList(contract);
    }

    @RequestMapping(value = "/updateContractStatusList",method = RequestMethod.POST)
    @ApiOperation(value = "合同状态数据修改接口",notes = "修改系统合同状态数据",httpMethod = "post", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code=500,message = "后台错误")
    })
    @ResponseBody
    //合同管理系统-合同状态-修改接口 12.07
    public R updateContractStatusList(@RequestBody Contract_status contract_status){

        return contractService.updateContractStatusList(contract_status);
    }

    @RequestMapping(value = "/updateContractRenewList",method = RequestMethod.POST)
    @ApiOperation(value = "合同续费接口",notes = "修改系统续费数据",httpMethod = "post", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code=500,message = "后台错误")
    })
    @ResponseBody
    //合同管理系统-续费-接口contract_renew 12.08
    public R updateContractRenewList(String contract_endday,Double contract_summoney,Double contract_receivemoney,Integer contract_id){

        return contractService.updateContractRenewList(contract_endday,contract_summoney,contract_receivemoney,contract_id);
    }



    @RequestMapping(value = "/updateContractReceive",method = RequestMethod.POST)
    @ApiOperation(value = "合同到款接口",notes = "合同到款数据",httpMethod = "post", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code=500,message = "后台错误")
    })
    @ApiImplicitParam(name = "contract_receivemoney",value = "到款金额",required = true,dataType = "Double",paramType = "query")
    @ResponseBody
    //合同管理系统-到款-接口contract_renew 12.08
    public R updateContractReceive(Double contract_receivemoney,Integer contract_id){


        return contractService.updateContractReceive(contract_receivemoney,contract_id);
    }






    @RequestMapping(value = "/insertNewContractList",method = RequestMethod.POST)
    @ApiOperation(value = "合同管理新增合同接口",notes = "新增合同",httpMethod = "post", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code=500,message = "后台错误")
    })

    @ResponseBody
    //合同管理系统-新增合同（第二步，新增合同）-接口 12.06
    @Transactional(rollbackFor = Exception.class)
    public R insertNewContractList(@RequestBody @ApiParam(name = "contract",value = "新增合同",required = true) Contract contract){
//        r.setCode(200);
//        r.setMsg("success");
//        r.setData(contract);
        return contractService.insertNewContractList(contract);
    }


    @RequestMapping(value = "/searchContractByName",method = RequestMethod.GET)
    @ApiOperation(value = "合同管理普通搜索接口",notes = "搜索合同数据",httpMethod = "get", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code=500,message = "后台错误")
    })
    @ResponseBody
   //合同管理系统-搜索合同数据-接口   12.08
    public R searchContractByName(String contract_search){


        return contractService.searchContractByName(contract_search);
    }

    @RequestMapping(value = "/searchContractByEntity",method = RequestMethod.GET)
    @ApiOperation(value = "合同管理普通搜索接口",notes = "搜索合同数据",httpMethod = "get", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code=500,message = "后台错误")
    })
    @ResponseBody
    //合同管理系统-高级搜索合同数据-接口
    public R searchContractByEntity(@RequestBody @ApiParam(name = "ContractByEntity",value = "高级搜索",required = true)Contract contract){
        R r=new R();
        r.setCode(200);
        r.setMsg("搜索成功");


        return contractService.searchContractByEntity(contract);
    }



    @RequestMapping(value = "/deleteContractByNo",method = RequestMethod.POST)
    @ApiOperation(value = "合同管理删除接口",notes = "删除合同数据",httpMethod = "post", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "删除成功"),
            @ApiResponse(code=500,message = "后台错误")
    })

    @ApiImplicitParam(name = "contract_no",value = "合同NO",required = true,dataType = "String",paramType = "query")


    @ResponseBody

    //删除合同记录将同时删除合同续费记录和对应财务记录 12.07
    public R deleteContractByNo(@RequestParam(value = "contract_no")String contract_no){

        return contractService.deleteContractByNo(contract_no);
    }


//
    @RequestMapping(value = "/searchContractByStartday",method = RequestMethod.GET)
    @ApiOperation(value = "合同管理每日新增合同查询接口",notes = "新增合同查询",httpMethod = "get", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code=500,message = "后台错误")
    })
    @ApiImplicitParam(name = "nowdate",value = "当前日期",required = true,dataType = "Date",paramType = "query")
    @ResponseBody
    //合同管理系统-每日新增合同查询-接口  SELECT * FROM contract WHERE TO_DAYS(contract_enterday) = TO_DAYS(NOW());
    public JsonResult searchContractByStartday(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit){

        return contractService.searchContractByStartday(page,limit);
    }

    @RequestMapping(value = "/searchContractByEndday",method = RequestMethod.GET)
    @ApiOperation(value = "合同管理每日到期合同查询接口",notes = "到期合同查询",httpMethod = "get", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code=500,message = "后台错误")
    })
    @ApiImplicitParam(name = "nowdate",value = "当前日期",required = true,dataType = "Date",paramType = "query")
    @ResponseBody
    //合同管理系统-每日到期合同查询-接口  SELECT * FROM contract WHERE TO_DAYS(contract_endday) = TO_DAYS(NOW());
    public JsonResult searchContractByEndday(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit){

        return contractService.searchContractByEndday(page,limit);
    }

    @RequestMapping(value = "/searchNewContractByWeek",method = RequestMethod.GET)
    @ApiOperation(value = "合同管理本周新增合同查询接口",notes = "新增合同查询",httpMethod = "get", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code=500,message = "后台错误")
    })
    @ApiImplicitParam(name = "nowdate",value = "当前日期",required = true,dataType = "Date",paramType = "query")
    @ResponseBody
    //合同管理系统-本周新增合同查询-接口 SELECT * FROM contract WHERE DATE_SUB(CURDATE(), INTERVAL 7 DAY) <=DATE(contract_enterday)
    public JsonResult searchNewContractByWeek(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit){

        return contractService.searchNewContractByWeek(page,limit);
    }


    @RequestMapping(value = "/searchDueContractByWeek",method = RequestMethod.GET)
    @ApiOperation(value = "合同管理本周到期合同查询接口",notes = "到期合同查询",httpMethod = "get", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code=500,message = "后台错误")
    })
    @ApiImplicitParam(name = "nowdate",value = "当前日期",required = true,dataType = "Date",paramType = "query")
    @ResponseBody
    //合同管理系统-本周到期合同查询-接口  SELECT * FROM contract WHERE DATE_SUB(CURDATE(), INTERVAL 7 DAY) <=DATE(contract_endday)
    public JsonResult searchDueContractByWeek(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit){

        return contractService.searchDueContractByWeek(page,limit);
    }

    @RequestMapping(value = "/searchDueContractByMonth",method = RequestMethod.GET)
    @ApiOperation(value = "合同管理本月到期合同查询接口",notes = "到期合同查询",httpMethod = "get", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code=500,message = "后台错误")
    })
    @ApiImplicitParam(name = "nowdate",value = "当前日期",required = true,dataType = "Date",paramType = "query")
    @ResponseBody
    //合同管理系统-本月到期合同查询-接口  SELECT * FROM contract WHERE DATE_FORMAT( contract_endday, '%Y%m' ) =DATE_FORMAT( CURDATE( ) , '%Y%m' )
    public JsonResult searchDueContractByMonth(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit){

        return contractService.searchDueContractByMonth(page,limit);
    }

    @RequestMapping(value = "/searchNewContractByMonth",method = RequestMethod.GET)
    @ApiOperation(value = "合同管理本月新增合同查询接口",notes = "到期合同查询",httpMethod = "get", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code=500,message = "后台错误")
    })
    @ApiImplicitParam(name = "nowdate",value = "当前日期",required = true,dataType = "Date",paramType = "query")
    @ResponseBody
    //合同管理系统-本月新增合同查询-接口  SELECT * FROM contract WHERE DATE_FORMAT( contract_enterday, '%Y%m' ) =DATE_FORMAT( CURDATE( ) , '%Y%m' )
    public JsonResult searchNewContractByMonth(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit){

        return contractService.searchNewContractByMonth(page,limit);
    }


    @RequestMapping(value = "/insertContractPart",method = RequestMethod.GET)
    @ApiOperation(value = "合同管理新增合同接口",notes = "新增合同",httpMethod = "post", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code=500,message = "后台错误")
    })

    @ResponseBody

    @Transactional(rollbackFor = Exception.class)
//合同管理系统-新增合同接口-接口
    public R insertContractPart(@RequestParam @ApiParam(name = "contract",value = "新增合同",required = true) String contract_newPart){

//        r.setCode(200);
//        r.setMsg("success");
//        r.setData(contract);
        return contractService.insertContractPart(contract_newPart);
    }








    @RequestMapping(value = "/queryContractAcc",method = RequestMethod.GET)
    @ApiOperation(value = "合同管理附件查询接口",notes = "附件查询数据",httpMethod = "get", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code=500,message = "后台错误")
    })
    @ResponseBody
    //合同管理系统-附件查询-接口
    public R queryContractAcc(@RequestBody @ApiParam(name = "Contract_acc",value = "附件查询",required = true) Contract_acc contract_acc){

        r.setCode(200);
        r.setData(contract_acc);
        r.setMsg("查询成功");
        return r;
    }

}
